package lc.Q200_250;

public class Q223 {

    public int computeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2) {
        // 两个矩形面积相加
        int area1 = (ax2 - ax1) * (ay2 - ay1);
        int area2 = (bx2 - bx1) * (by2 - by1);
        // 阴影部分面积
        int overlapWidth = Integer.min(ax2, bx2) - Integer.max(ax1, bx1);
        int overlapHeight = Integer.min(ay2, by2) - Integer.max(ay1, by1);
        int overlap = Integer.max(overlapWidth, 0) * Integer.max(overlapHeight, 0);
        return area1 + area2 - overlap;
    }

    public static void main(String[] args) {
        Q223 q223 = new Q223();
        System.out.println(q223.computeArea(-3,0,3,4,0,-1,9,2));
    }
}
